package com.remoter.consumer.internal;

import com.remoter.basic.bean.support.ConsumerModule;
import com.remoter.basic.consumer.support.AbstractConsumer;
import com.remoter.basic.proxy.IProxy;
import com.remoter.basic.util.Final;
import com.remoter.basic.util.ServiceLoader;
import com.remoter.basic.util.ServiceLoader.MetaName;

/**
 * @author			koko
 * @date 			2017-08-08 13:24:49
 * @description 	类功能说明
 */
@MetaName("internal")
public class InternalConsumer extends AbstractConsumer{
	
	protected final IProxy proxy;
	
	public InternalConsumer(){
		this.proxy = ServiceLoader.getService(IProxy.class,this.configuration.getOption(Final.O_VAL_PROXY));
	}
	
	@Override
	protected Object createProxy(ConsumerModule consumerModule)throws Exception{
		Class<?> type = Class.forName(consumerModule.getType());
		Object obj = this.proxy.createInstance(Thread.currentThread().getContextClassLoader(),new Class<?>[]{type},new InternalInvoker().init(configuration, this, consumerModule));
		consumerModule.setProxy(obj);
		return obj;
	}

}